package database;

import java.sql.Connection;

import org.apache.log4j.Logger;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;

public class Bonecp {

	private Logger log = Logger.getLogger(Bonecp.class);

	private Connection con = null;	

	public Connection getConnection() {

		try {
			if (con == null) {

				Class.forName("com.mysql.jdbc.Driver");
				BoneCPConfig config = new BoneCPConfig();

				config.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/yangchicao?useUnicode=true&characterEncoding=utf-8");

				config.setUsername("root");
				config.setPassword("root");
				
				config.setMinConnectionsPerPartition(5);
				
				config.setMaxConnectionsPerPartition(10);

				BoneCP connectionPool = new BoneCP(config);

				con = connectionPool.getConnection();
				
				return con;
			} else {
				return con;
			}

		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
}
